package concurrent;

import lombok.extern.slf4j.Slf4j;

/**
 * @author fengpeng
 * @date 2019-08-29  18:43
 */
@Slf4j
public class ThreadJoinDemo {


    public static void main(String[] args){
        Object oo = new Object();
        MyThread t1 = new MyThread("线程t1--", oo);
        MyThread t2 = new MyThread("线程t2--", oo);
        t2.start();
        t1.start();
        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("main end ...!");
    }




 static  class MyThread extends Thread{
        private String name;
        private Object oo;
        public MyThread(String name,Object oo){
            this.name = name;
            this.oo = oo;
        }
        @Override
        public void run() {
            synchronized (oo) {
                for(int i = 0; i < 1000; i++){
                    log.info(name + i);
                }
            }
        }
    }


}
